﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace AnimalWars2
{
    public class MovableEntity : Entity
    {
        public Vector2 m_Vel = new Vector2(0.0f, 0.0f);
        public float m_Accel = 500.0f;
        public float m_MaxVel = 75.0f;

        public MovableEntity(Game GameRef, Texture2D Tex, Vector2 Pos, Vector2 Vel)
            : base(GameRef, Pos, Tex)
        {
            m_Vel = Vel;
        }

        public virtual Vector2 GetMoveDir()
        {
            return Vector2.Zero;
        }

        public override void Update(GameTime gameTime)
        {
            float DeltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            Vector2 vMoveDir = GetMoveDir();

            if (vMoveDir.Length() > 0.0f)
            {
                vMoveDir.Normalize();

                m_Vel += vMoveDir * m_Accel * DeltaTime;

                if (m_Vel.Length() > m_MaxVel)
                {
                    m_Vel.Normalize();
                    m_Vel *= m_MaxVel;
                }
            }
            else
            {
                float Mag = m_Vel.Length();

                float Friction = 8.0f;

                if (Mag > 0.0f)
                {
                    float Mul = (Mag - Mag * Friction * DeltaTime) / Mag;

                    m_Vel *= Mul;
                }

            }

            m_Pos += m_Vel * DeltaTime;
        }
    }
}
